package com.education.platform.management.controller.user;

import com.education.platform.common.util.BeanUtil;
import com.education.platform.dao.entity.PayRecordDO;
import com.education.platform.dao.model.PayRecordModel;
import com.education.platform.management.service.PayRecordService;
import com.education.platform.management.vo.request.PayRecordQueryVO;
import com.education.platform.management.vo.response.PayRecordPageInfoVO;
import com.education.platform.management.vo.response.PayRecordResponseVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* describe: 支付记录
* @author : tomato
* @date: 2020-06-29 10:28:07.761
**/
@RestController
@Api("充值记录")
@RequestMapping("payRecord")
@Validated
public class PayRecordController {

    private static final Logger LOGGER = LoggerFactory.getLogger(PayRecordController.class);

	@Autowired
    private PayRecordService payRecordService;
    /**
     * 分页查询
     * @param payRecordQueryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public PayRecordPageInfoVO selectPageList(@RequestBody @Valid PayRecordQueryVO payRecordQueryVO) {
        String info = String.format("The method name[selectPageList] params:%s", payRecordQueryVO.toString());
        LOGGER.info(info);
        PayRecordModel payRecord = BeanUtil.convert(payRecordQueryVO, PayRecordModel.class);

        Page<PayRecordResponseVO> page = PageHelper.startPage(payRecordQueryVO.getPageNum(), payRecordQueryVO.getPageSize());
        List<PayRecordModel> payRecordList = payRecordService.getPayRecordList(payRecord);
        PayRecordPageInfoVO payRecordPageInfo = new PayRecordPageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), payRecordPageInfo);
        payRecordPageInfo.setPageNum(payRecordQueryVO.getPageNum());
        List<PayRecordResponseVO> voList = BeanUtil.convert(payRecordList, PayRecordResponseVO.class);
        payRecordPageInfo.setList(voList);

        return payRecordPageInfo;
    }


}
